<?php
	// Check crossing acess
	if (!defined('RIGHT_ACCESS') || !defined('ROOT_FOLDER'))
	{
		header('Content-Type: text/xml; charset=utf-8');
		echo '<?xml version="1.0"?>';
		echo '<atomtask>';
		echo '<request>error.request.invalid</request>';
		echo '</atomtask>';
		return;
	}	

	// Include functions
	include_once(ROOT_FOLDER.'includes/xml_func.php');
	include_once(ROOT_FOLDER.'includes/project_func.php');
	include_once(ROOT_FOLDER.'api/auth.php');

	// Check enough information
	if (!isset($_POST['project_name']) || !isset($_POST['project_description']))
	{
		XML::write_element('result', 'error.project.create_project.invalid_input');
		return;
	}

	// Authorize
	if (!isset($valid_auth) || !$valid_auth)
		return;

	// Create project
	$project = new Project();
	$project->project_name = Text::standardize($_POST['project_name']);
	$project->project_description = Text::standardize($_POST['project_description']);
	$project->creator_id = $auth->user_id;
	if (!$project->create())
	{
		XML::write_element('result', 'error.request.unknown');
		return;
	}
	XML::write_element('result', 'success.project.create_project');
?>